layui.use(['form','layer','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laytpl = layui.laytpl,
        table = layui.table;

    //检验项目列表
    var tableIns4=table.render({
        elem:'#userlist4',
        url: 'http://101.201.56.140:10086/pc/InspectItem/seeAll',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limits : [10,15,20,25],
        limit : 20,
        id : "userListTable4",
        cols:[[
            {type:'checkbox',fixed:'left',width:50},
            {field:'inspectItemID',title: '检验项目ID',align: 'center',width: 100},
            {field:'inspectItemName',title:'检验项目名称',align:'center'},
            {field: 'inspectTypeID',title: '检验类型',align: 'center'},
            {
                field: 'inspectTypeClass', title: '检验分类', width:100,align: 'center', templet: function (d) {
                    if (d.inspectTypeClass == "0") {
                        return "质量";
                    } else if (d.inspectTypeClass == "1") {
                        return "安全";
                    }
                }
            },
            {field: 'rm',title: '关系映射',align: 'center',templet:'#RM',width: 200},
            {title: '操作',minWidth:175,templet:'#userListBar',fixed: 'right',align: 'center'}

        ]]
    })

    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").click(function () {
        var inputVal = $('.layui-input ').val();

        table.reload('userListTable', {

            url: 'http://101.201.56.140:10086/pc/InspectItem/selByID',
            method: 'post',
            request: {
                statusName: 'status',
                // pageName:'pageNum',
                // limitName: 'pageSize'
            },
            where: {
                inspectTypeID: inputVal,
                status: 0

            },
            page: {
                curr: 1
            }

        })
    })

    //添加用户
    function addUser(edit){
        var index = layui.layer.open({
            title : "添加类型",
            type : 2,
            content : "../dataAdd/TypeAdd.html",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                if(edit){
                    body.find(".testType").val(edit.testType);  //检验类型名称
                    body.find(".testClassify").val(edit.testClassify);  //检验分类
                    body.find(".testDepict").text(edit.testDepict);    //检验描述
                    form.render();
                }
                setTimeout(function(){
                    layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index",index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }
    $(".addNews_btn").click(function(){
        addUser();
    })

    //批量删除
    $(".delAll_btn").click(function(obj){
        var checkStatus = table.checkStatus('userListTable4'),
            data = checkStatus.data,
            newsId = [];
        if(data.length > 0) {
            for (var i in data) {
                newsId.push(data[i].newsId);
            }
            layer.confirm('确定删除选中的项目？', {icon: 3, title: '提示信息'}, function (index) {
                $.post("http://101.201.56.140:10086/pc/InspectItem/deletes",{
                    newsId : newsId  //将需要删除的newsId作为参数传入
                },function(data){
                newsId.
                layer.close(index);

                })
            })
        }else{
            layer.msg("请选择需要删除的项目");
        }
    })

    //方法
    function ItemMethod(edit){
        var index = layui.layer.open({
            title : "方法",
            type : 2,
            content : "../btn in list/ItemMethod.html",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function(){
                    layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index",index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }

    //标准
    function ItemStandard(edit){
        var index = layui.layer.open({
            title : "标准",
            type : 2,
            content : "../btn in list/ItemStandard.html",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function(){
                    layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index",index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }


    //列表操作
    table.on('tool(userlist4)', function(obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                addUser(data);
                break;
            case 'del':
                layer.confirm('确定删除此项目？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post({
                        datatype: 'json',
                        url: 'http://101.201.56.140:10086/pc/InspectItem/delete',
                        data: {'inspectStandardID': data.inspectStandardID},
                    })
                    obj.del();
                    layer.close(index);

                })
                    break;
            case 'ItemMethod':
                ItemMethod(data);
                break;
            case 'ItemStandard':
                ItemStandard(data);
                break;

        }
    })

})